﻿//删除图片
function RemoveImage(delBtn) {
    var imgUrl = jQuery(delBtn).parent().children("img").attr("src");
    jQuery(delBtn).parent().remove();
    if (imgUrl.length > 0) {
        var data = new Object();
        data.ImageUrl = imgUrl;
        var url= "/AjaxService/UploadImages.ashx?doing=2";
        jQuery.ajax({
            url:url,
            data:data,
            type:"post",
            dataType:"json",
            success:function(data){
                alert(data);
            },
            error:function(){
            }
        });
    }
}


//初始化swfupload
function InitSwfUpload(sessionId) {
    var swfu;
    swfu = new SWFUpload({
        // Backend Settings
        upload_url: "/AjaxService/UploadImages.ashx?doing=1",
        file_post_name: "Filedata",
        post_params: { "ASPSESSID": sessionId },

        // File Upload Settings
        file_size_limit: "2.5 MB",
        file_types: "*.jpg;*.jpeg;*.gif;*.png",
        file_types_description: "图片",
        file_upload_limit: "0",
        file_queue_limit: "0",
        file_queued_handler: function (file) {
            this.customSettings.queue = this.customSettings.queue || new Array();
            this.customSettings.queue.push(file.id);
            //得到已上传图片的数量
            var imageCount = jQuery("#ImageContainer>span").length;
            if (imageCount > 0) {
                alert("文章焦点图只允许上传一张!");
                while (this.customSettings.queue.length > 0) {
                    this.cancelUpload(this.customSettings.queue.pop(), false);
                }               
            }
            else if (this.customSettings.queue.length > 1) {
                while (this.customSettings.queue.length > 0) {
                    this.cancelUpload(this.customSettings.queue.pop(), false);
                }                
            }
        },

        // Event Handler Settings
        file_queue_error_handler: fileQueueError,
        file_dialog_complete_handler: fileDialogComplete,
        upload_progress_handler: uploadProgress,
        upload_error_handler: uploadError,
        upload_success_handler: uploadSuccess,
        upload_complete_handler: uploadComplete,
        upload_customer_setting: function (file) {

        },

        // Button settings
        button_image_url: "/Scripts/Cms/swfupload/images/buttonswf.jpg",
        button_placeholder_id: "UploadButtonContainer",
        button_width: 90,
        button_height: 23,
        button_text: '上传文件',
        button_text_style: 'background:url(/Scripts/Cms/swfupload/images/buttonswf.jpg); width:90px; height:23px; border:0px; cursor:pointer; color:#333; line-height:23px; text-align:center;',
        button_text_top_padding: 1,
        button_text_left_padding: 15,

        // Flash Settings
        flash_url: "/Scripts/Cms/swfupload/swfupload.swf", // Relative to this file

        // Debug Settings
        debug: false
    });
}
